package com.qyhl.module_practice.score.shop;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeShopListBean;

import java.util.List;

public class PracticeScoreShopModel implements PracticeScoreShopContract.PracticeScoreShopModel {
    private PracticeScoreShopPresenter mPresenter;

    PracticeScoreShopModel(PracticeScoreShopPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(final String page) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_SCORE_SHOPPING_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("page", page)
                .execute(new SimpleCallBack<List<PracticeShopListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无更多内容", !page.equals("1"));
                        } else {
                            mPresenter.setError("获取失败，请稍后再试！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<PracticeShopListBean> practiceShopListBeans) {
                        if (practiceShopListBeans != null && practiceShopListBeans.size() > 0) {
                            mPresenter.setList(practiceShopListBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无更多内容", !page.equals("1"));
                        }
                    }
                });
    }
}
